home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cenvid9.zip / MULTIDIR.BAT < prev    next >
DOS Batch File  |  1994-03-04  |  4KB  |  99 lines

  1. @echo off
  2. REM *********************************************************************
  3. REM *** MultiDir.bat - Display directories allowing for multiple file ***
  4. REM *** ver.1          specifications.                                ***
  5. REM ***                Example: MultiDir *.txt *.doc read*.*          ***
  6. REM *********************************************************************
  7.  
  8. REM *************************************************************************
  9. REM *** The Cmm code uses a temporary file to store temporary DIR output. ***
  10. REM *** Define that name here.  The file will be removed at the end of    ***
  11. REM *** this batch file.  If you want to alter the location of this       ***
  12. REM *** temp file, perhaps to be on a ramdisk, then alter it here.        ***
  13. REM *************************************************************************
  14.  
  15. SET MULTIDIR_FILENAME=%TEMP%\MultiDir.tmp
  16. if exist %MULTIDIR_FILENAME% del %MULTIDIR_FILENAME%
  17.  
  18.  
  19. REM *****************************
  20. REM *** Let CEnvi do the rest ***
  21. REM *****************************
  22. CEnvi %0.bat %1 %2 %3 %4 %5 %6 %7 %8 %9
  23. GOTO CENVI_EXIT
  24.  
  25. main(argc,argv)
  26. {
  27.    // check if help is being requested
  28.    if ( 2 == argc
  29.      && ( !stricmp(argv[1],"/?") || !stricmp(argv[1],"/help") ) ) {
  30.       Instructions();
  31.    } else {
  32.       // collect all flags, which will be passed on to dir
  33.       FlagCount = 0;
  34.       for ( flags = "", arg = 1; arg < argc; arg++ ) {
  35.          if ( '/' == argv[arg][0] ) {
  36.             strcat(strcat(flags,argv[arg])," ");
  37.             FlagCount++;
  38.          }
  39.       }
  40.       if ( FlagCount == (argc-1) ) {
  41.          // no filespec parameters were specified, and so simply to the dir call
  42.          system("dir %s",flags);
  43.       } else {
  44.          // for each filespec in input parameters, pipe output of the dir command
  45.          // to the temporary file
  46.          for ( arg = 1; arg < argc; arg++ ) {
  47.             if ( '/' != argv[arg][0] ) {
  48.                system("dir %s %s >> %s",argv[arg],flags,MULTIDIR_FILENAME);
  49.             }
  50.          }
  51.          // Read in each line from the Temporary filename and print it with
  52.          // the single exception that if the line has already been printed then
  53.          // don't print it.  This removes the problem of multiple printing of
  54.          // filespecs when the filename matches more than one of the input
  55.          // specs, and also keeps us from writing the volume labels and other
  56.          // stuff more than once.
  57.          fp = fopen(MULTIDIR_FILENAME,"r");
  58.          assert( NULL != fp );
  59.          Total = 0;
  60.          while ( NULL != (line = fgets(fp))) {
  61.             // don't print the bytes used or the bytes free
  62.             if ( NULL == strstr(line,"bytes free") && NULL == strstr(line,"bytes used") ) {
  63.                // don't print if already printed
  64.                for ( i = 0; i < Total; i++ ) {
  65.                   if ( !strcmp(line,DirList[i]) )
  66.                      break;
  67.                }
  68.                if ( i == Total ) {
  69.                   printf("%s",line);
  70.                   DirList[Total++] = line;
  71.                }
  72.             }
  73.          }
  74.          fclose(fp);
  75.       }
  76.    }
  77. }
  78.  
  79. Instructions()
  80. {
  81.    printf("\n")
  82.    printf("MultiDir - Execute the system DIR command on multiple file-specs.\n")
  83.    printf("\n")
  84.    printf("SYNTAX: MultiDir [flags] [FileSpec1 [FileSpec2 [...]]]\n")
  85.    printf("\n")
  86.    printf("Where:  flags    - options passed on to the DIR command\n")
  87.    printf("        FileSpec - FileSpec defines set of drive:filename files to list\n")
  88.    printf("\n")
  89.    printf("Example: MULTIDIR *.doc *.txt /b\n")
  90.    printf("\n")
  91. }
  92.  
  93. :CENVI_EXIT
  94. REM *************************************************************
  95. REM *** The CEnvi portion is finished.  Remove the temp file. ***
  96. REM *************************************************************
  97. if exist %MULTIDIR_FILENAME% del %MULTIDIR_FILENAME% > NUL
  98. set MULTIDIR_FILENAME=
  99.